let arr1 = [1, 2, 3, 4, 2, 1] 
let arr2 = [2, 3, 5, 7, 5] 

let s1 = new Set(arr1) 
let s2 = new Set(arr2) 
let result = new Set(arr1.filter(item => s2.has(item))) 

console.log("交集为："+Array.from(result))

let arr3 = new Set(arr1.filter(item => !s2.has(item))) 
let arr4 = new Set(arr2.filter(item => !s1.has(item))) 

console.log("差集为："+[...arr3, ...arr4])

//使用递归的方式实现数组、对象的深拷贝
function deepClone(obj) {
    //判断拷贝的要进行深拷贝的是数组还是对象，是数组的话进行数组拷贝，对象的话进行对象拷贝
    var objClone = Array.isArray(obj) ? [] : {};
    if (obj && typeof obj === "object") {
      for (let key in obj) {
        if (obj.hasOwnProperty(key)) {
          if (obj[key] && typeof obj[key] === "object") {
            objClone[key] = deepClone(obj[key]);
          } else {
            objClone[key] = obj[key];
          }
        }
      }
    }
    return objClone;
  } 

let arr5 = [{a:'1',b:'2',c:'3'},{aa:'11',bb:'22',cc:'33'},{aaa:'111',bbb:'222',ccc:'333'}];
let arr6 = arr5;
arr5[2].ccc='444';
console.log(arr5); //[{a:'1',b:'2',c:'3'},{aa:'11',bb:'22',cc:'33'},{aaa:'111',bbb:'222',ccc:'444'}]
console.log(arr6); //[{a:'1',b:'2',c:'3'},{aa:'11',bb:'22',cc:'33'},{aaa:'111',bbb:'222',ccc:'444'}]

arr5 = [{a:'1',b:'2',c:'3'},{aa:'11',bb:'22',cc:'33'},{aaa:'111',bbb:'222',ccc:'333'}];
arr6 = deepClone(arr5);
arr5[2].ccc='444';
console.log(arr5); //[{a:'1',b:'2',c:'3'},{aa:'11',bb:'22',cc:'33'},{aaa:'111',bbb:'222',ccc:'444'}]
console.log(arr6); //[{a:'1',b:'2',c:'3'},{aa:'11',bb:'22',cc:'33'},{aaa:'111',bbb:'222',ccc:'333'}] 